const Joi = require('joi');
const { password } = require('./custom.validator');

/**
 * 注册验证
 */
const register = {
  body: Joi.object().keys({
    name: Joi.string().required(),
    email: Joi.string().required().email(),
    password: Joi.string().required().custom(password),
  }),
};

/**
 * 登录验证
 */
const login = {
  body: Joi.object().keys({
    email: Joi.string().required(),
    password: Joi.string().required(),
  }),
};

/**
 * 刷新令牌验证
 */
const refreshTokens = {
  body: Joi.object().keys({
    refreshToken: Joi.string().required(),
  }),
};

/**
 * 登出验证
 */
const logout = {
  body: Joi.object().keys({
    refreshToken: Joi.string().required(),
  }),
};

/**
 * 忘记密码验证
 */
const forgotPassword = {
  body: Joi.object().keys({
    email: Joi.string().email().required(),
  }),
};

/**
 * 重置密码验证
 */
const resetPassword = {
  query: Joi.object().keys({
    token: Joi.string().required(),
  }),
  body: Joi.object().keys({
    password: Joi.string().required().custom(password),
  }),
};

/**
 * 验证邮箱验证
 */
const verifyEmail = {
  query: Joi.object().keys({
    token: Joi.string().required(),
  }),
};

const wxLogin = {
  body: Joi.object().keys({
    code: Joi.string().required().messages({
      'string.empty': '微信临时登录凭证不能为空',
      'any.required': '微信临时登录凭证是必填项'
    })
  })
};

module.exports = {
  register,
  login,
  refreshTokens,
  logout,
  forgotPassword,
  resetPassword,
  verifyEmail,
  wxLogin,
}; 